<!--
 * @Author: your name
 * @Date: 2021-11-11 11:41:31
 * @LastEditTime: 2021-11-11 11:52:39
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue-note\day01\13.v-bind动态绑定class属性.html
-->
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>13.v-bind动态绑定class属性</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
    <style>
      .active {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 固定的class直接写class -->
      <!-- 类名1：true，类型2：true-->
      <div class="title" :class="{active: isActive}">{{msg}}</div>
      <!-- 函数写法，放在methods中 -->
      <div class="title" :class="getClasses()">{{msg}}</div>
      <button @click="handleColor">点击</button>
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          msg: "hello",
          isActive: true,
        },
        methods: {
          handleColor() {
            this.isActive = this.isActive ? false : true;
          },
          getClasses() {
            return { active: this.isActive };
          },
        },
      });
    </script>
  </body>
</html>
